home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / timer.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  2.8 KB  |  128 lines

  1. /*
  2.     File:        Timer.cp
  3.  
  4.     Contains:    TTimer is a simple timing class that could provide both 10 lap time values as well as
  5.                   final values.
  6.                   TTimer.cp contains the TTimer member functions.
  7.  
  8.     Written by: Kent Sandvik    
  9.  
  10.     Copyright:    Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25. #ifndef _TIMER_
  26. #include "Timer.h"
  27. #endif
  28.  
  29.  
  30. // _________________________________________________________________________________________________________ //
  31. //    TTimer Class definitions.
  32.  
  33. //    CONSTRUCTORS AND DESTRUCTORS
  34. #pragma segment Timer
  35. TTimer::TTimer()
  36. // Default constructor.
  37. {
  38.     this->Reset();
  39. }
  40.  
  41.  
  42. #pragma segment Timer
  43. TTimer::~TTimer()
  44. // Default destructor -- empty for the time being.
  45. {
  46. }
  47.  
  48.  
  49. //    MAIN INTERFACES
  50. #pragma segment Timer
  51. void TTimer::Start()
  52. // Start the timer.
  53. {
  54.     fStartTick = ::TickCount();
  55. }
  56.  
  57.  
  58. #pragma segment Timer
  59. void TTimer::Stop()
  60. // Stop the timer.
  61. {
  62.     fStopTick = ::TickCount();
  63. }
  64.  
  65. #pragma segment Timer
  66. void TTimer::Reset()
  67. // Reset the internal count to zero.
  68. {
  69.     fStartTick = fStopTick = 0;
  70. }
  71.  
  72.  
  73. #pragma segment Timer
  74. void TTimer::SetLap(short index)
  75. // Set a lap time, where we have 10 lap registers.
  76. {
  77.     VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
  78.     if (index < 11)
  79.         fLapIndex[index] = ::TickCount() - fStartTick;
  80. }
  81.  
  82.  
  83. #pragma segment Timer
  84. long TTimer::GetLap(short index)
  85. // Get the lap time, we have 10 lap registers.
  86. {
  87.     VASSERT(index < 11, ("Index is bigger than 10 = %d\n", index));
  88.     if (index < 11)
  89.         return fLapIndex[index];
  90.     else
  91.         return 0;
  92. }
  93.  
  94.  
  95. #pragma segment Timer
  96. long TTimer::GetLap()
  97. // Get a temporary lap time, independent of the registers.
  98. {
  99.     long temp = ::TickCount();
  100.     return (temp - fStartTick);
  101. }
  102.  
  103.  
  104. #pragma segment Timer
  105. long TTimer::GetTicks()
  106. // Get tick count from when we started the timer.
  107. {
  108.     return (fStopTick - fStartTick);
  109. }
  110.  
  111.  
  112. #pragma segment Timer
  113. float TTimer::GetSeconds()
  114. // Get N seconds from the point of time when we started the timer.
  115. {
  116.     return ((float)(fStopTick - fStartTick) / 60L);
  117. }
  118.  
  119.  
  120. // _________________________________________________________________________________________________________ //
  121.  
  122.  
  123. /*    Change History (most recent last):
  124.   No        Init.    Date        Comment
  125.   1            khs        12/14/92    New file
  126.   2            khs        1/3/93        Cleanup
  127. */
  128.